
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Knowledge Graph - Entities</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-4">
    <h1>Knowledge Graph Entities</h1>

    <div class="mb-3">
        <a href="/knowledge-graph/entity/new" class="btn btn-primary">Add New Entity</a>
    </div>

    <div th:if="${entities == null or entities.empty}" class="alert alert-warning">
        No entities found in the knowledge graph.
    </div>

    <table class="table table-striped" th:unless="${entities == null or entities.empty}">
        <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Type</th>
            <th>Description</th>
            <th>Actions</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="entity : ${entities}">
            <td th:text="${entity?.id ?: 'N/A'}"></td>
            <td>
                <a th:href="@{${entity?.name != null} ?
                        '/knowledge-graph/entity/' + ${entity.name} : '#'}"
                   th:text="${#strings.defaultString(entity.name, 'Unnamed')}"></a>
            </td>
            <td th:text="${#strings.defaultString(entity.type, 'Unknown')}"></td>
            <td th:text="${#strings.defaultString(entity.description, '--')}"></td>
            <td>
                <a th:href="@{${entity?.name != null} ?
                        '/knowledge-graph/entity/' + ${entity.name} + '/add-relation' : '#'}"
                   class="btn btn-sm btn-outline-secondary">Add Relation</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>
